#!/usr/bin/python
import ConfigParser
import datetime

class ZpFile:
	
	def __init__(self, file_zp):
		self.filezp = open(file_zp, "w")
		self.confg = ConfigParser.RawConfigParser()
	
	def insertInfo(self, infodict):
		package_name = infodict["package_name"]
		package_version = infodict["package_version"]
		package_website = infodict["package_website"]
		author_name = infodict["author_name"]
		author_email = infodict["author_email"]
		zp_version = infodict["zp_version"]
		if infodict["zp_date"] == "":
			zp_date = datetime.datetime.now().strftime("%d/%m/%y")
		else:
			zp_date = infodict["zp_date"]
		self.confg.add_section("info")
		self.confg.set("info", "name", package_name)
		self.confg.set("info", "version", package_version)
		self.confg.set("info", "website", package_website)
		self.confg.set("info", "author", author_name)
		self.confg.set("info", "email", author_email)
		self.confg.set("info", "zp version", zp_version)
		self.confg.set("info", "creation date", zp_date)
	
	def insertSource(self, source_url):
		self.confg.add_section("source")
		self.confg.set("source", "source", source_url)
		
	def insertDependencies(self, dependencies):
		self.confg.add_section("dependencies")
		numb = 1
		for dp in dependencies:
			dep_number = "dep%d" % numb
			self.confg.set("dependencies", dep_number, dp)
			numb+=1
	
	def insertCompilerOptions(self, compiler_options):
		self.confg.add_section("compiler-option")
		self.confg.set("compiler-option", "opt", compiler_options)
	
	def writeZp(self, file_zp):
		with open(file_zp, "wb") as confgfile:
			self.confg.write(confgfile)
